#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	int n;
	while (cin>>n)
	{
		int i = 1;
		int sum = 0;
		for (; i <= n; i++) {
			if (i % 10 != 7 && i / 10 != 7 && i % 7 != 0) {
				sum += i * i;
			}
		}
		cout << sum<<endl;
	}
}

#include <iostream>

using namespace std;


int main(int argc, char* argv[])
{
	int n;
	
	int yearS = 31536000;
	int dayS = 86400;
	int thM = 2592000;
	int foM = 2678400;
	int teM = 2419200;
	int tnM = 2505600;
	while (cin>>n)
	{
		int startYear = 1970;
		int startMonth = 1;
		int startDay = 1;
		int startHour = 0;
		int startMinute = 0;
		int startSecond = 0;

		int absStartYear = n / yearS;
		n = n % yearS;
		
		for (int i = 0; i < absStartYear; i++) {
			if ((startYear + i) % 4 == 0) {
				n -= dayS;
				if (n <= 0) {
					absStartYear--;
					n += yearS;
				}
			}
		}

		startYear += absStartYear;
		int elapsed = 0;
		int preElapsed = 0;
		while (elapsed <= n) {
			preElapsed = elapsed;			
			switch (startMonth) {
				case 1: case 3: case 5: case 7: case 8: case 10: case 12:
					elapsed += foM;
				    break;
				case 4: case 6: case 9: case 11:
					elapsed += thM;
					break;
				case 2:
					if (startYear % 4 == 0) {
						elapsed += tnM;
					} else {
						elapsed += teM;
					}
					break;
				default:
					break;
			}			
			++startMonth;
		}
		--startMonth;

		n -= preElapsed;
		elapsed = 0;
		while (elapsed <= n) {
			preElapsed = elapsed;
			++startDay;
			elapsed += dayS;
		}
		--startDay;

		n -= preElapsed;
		elapsed = 0;
		while (elapsed <= n) {
			preElapsed = elapsed;
			++startHour;
			elapsed += 3600;
		}

		--startHour;
		n -= preElapsed;
		elapsed = 0;

		while (elapsed <= n) {
			preElapsed = elapsed;
			++startMinute;
			elapsed += 60;
		}

		--startMinute;
		n -= preElapsed;
		elapsed = 0;

		while (elapsed <= n) {
			preElapsed = elapsed;
			++startSecond;
			elapsed ++;
		}

		--startSecond;
		n -= preElapsed;
		
		cout << startYear<<"-";
		const int length = 3;
		char str[length];
		for (int i = 0; i < length; i++) {
			str[i] = 0;
		}
		str[0] = startMonth / 10 + '0';
		str[1] = startMonth % 10 + '0';
		cout << str << "-";

		
		str[0] = startDay / 10 + '0';
		str[1] = startDay % 10 + '0';
		cout << str << " ";

		
		str[0] = startHour / 10 + '0';
		str[1] = startHour % 10 + '0';
		cout << str << ":";

		
		str[0] = startMinute / 10 + '0';
		str[1] = startMinute % 10 + '0';
		cout << str << ":";

		
		str[0] = startSecond / 10 + '0';
		str[1] = startSecond % 10 + '0';
		cout << str << endl;		
	}
	return 0;
}


#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	const int length = 1001;
	int T;
	cin>>T;
	while (T > 0) {
		int A, C;
		char B[length];
		
		int i;
		for (i = 0; i < length; i++) {
			B[i] = 0;
		}

		cin>>A>>B>>C;
		int radix = 1;
		for (i = 0; i < length; i++) {
			if (B[i] != 0)
				radix ++;
			else
				break;
		}
				
		int ra[length];
		for (i = 0; i < length; i++) {
			ra[i] = 0;
		}
		int rc[length];
		for (i = 0; i < length; i++) {
			rc[i] = 0;
		}
		int rResult[length];

		i = 0;
		int j = 0;
		int k = 0;
		while (A > 0 || C > 0) {
			if (A > 0) {
				ra[i] = A % radix;
				A = (A -  ra[i]) / radix;
			}
			else
				ra[i] = 0;
			if (C > 0) {
				rc[j] = C % radix;
				C = (C - rc[j]) / radix;
			}
			else
				rc[j] = 0;
			
			rResult[k] = (ra[i] + rc[j]) % radix;
			++i;
			++j;
			++k;
		}
		int fResult = 0;
		int pow = 1;
		for (i = 0; i < k; i++) {
			fResult += (pow * rResult[i]);
			pow *= radix;
		}
		cout<<fResult<<endl;

		--T;
	}
	return 0;
}